package com.wsjzzcbq.qianyuan.sys.controller;

import com.wsjzzcbq.qianyuan.common.bean.PageBean;
import com.wsjzzcbq.qianyuan.common.bean.R;
import com.wsjzzcbq.qianyuan.sys.param.AddSysUserParam;
import com.wsjzzcbq.qianyuan.sys.param.FindSysUserListParam;
import com.wsjzzcbq.qianyuan.sys.param.LoginParam;
import com.wsjzzcbq.qianyuan.sys.service.SysUserService;
import com.wsjzzcbq.qianyuan.sys.vo.LoginVo;
import com.wsjzzcbq.qianyuan.sys.vo.SysUserInfoVo;
import com.wsjzzcbq.qianyuan.sys.vo.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * SysController
 *
 * @author wsjz
 * @date 2022/03/10
 */
@RequestMapping("/sys/user")
@RestController
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody @Valid LoginParam param) {
        return sysUserService.login(param);
    }

    @GetMapping(value = "/getUserInfo")
    public R<SysUserInfoVo> getUserInfo(String token) {
        return sysUserService.getSysUserInfo(token);
    }

    @PostMapping(value = "/logout")
    public R<?> logout() {
        return sysUserService.logout();
    }

    @PostMapping(value = "/findList")
    public R<PageBean<SysUserVo>> findList(@RequestBody FindSysUserListParam param) {
        return sysUserService.findList(param);
    }

    @PostMapping(value = "/addOrUpdate")
    public R<?> addOrUpdate(@RequestBody @Valid AddSysUserParam param) {
        return sysUserService.addOrUpdate(param);
    }

    @GetMapping("/findSysUserById")
    public R<?> findSysUserById(@RequestParam("id") String id) {
        return sysUserService.findSysUserById(id);
    }

    @DeleteMapping("/deleteSysUserById")
    public R<?> deleteSysUserById(@RequestParam("id") String id) {
        return sysUserService.deleteSysUserById(id);
    }
}
